<!DOCTYPE html>
<html>
  <head> 
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="./favicon.ico">
    <link rel="stylesheet" href="./css/bootstrap.min.css" />
    <script src="./js/jquery-3.3.1.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <title>静态资管理系统</title>
    <style>
      [hidden] {
        display: none;
      }
    </style>
  </head>
  <body>
    <div class="panel panel-default" style="width: 600px;margin: 30px auto 0;">
      <div class="panel-heading">
        <h3 class="panel-title">静态资源上传</h3>
      </div>
      <div class="panel-body">
        <form
          id="form-box"
          class="form-horizontal"
          role="form"
          action="/uploaddir"
          method="post"
          enctype="multipart/form-data"
        >
          <div class="form-group">
            <label for="projectname" class="col-sm-3 control-label">项目名称</label>
            <div class="col-sm-9">
              <input
                maxlength="20"
                type="text"
                class="form-control"
                id="projectname"
                name="projectname"
                placeholder="请输入项目名称"
              />
            </div>
          </div>
          <div class="form-group">
            <label for="projectname" class="col-sm-3 control-label">项目版本号</label>
            <div class="col-sm-9">
              <input
                maxlength="20"
                type="text"
                class="form-control"
                id="projectversion"
                name="projectversion"
                placeholder="项目版本号"
              />
            </div>
          </div>
          <div class="form-group">
            <label for="directoryInput" class="col-sm-3 control-label">选择文件夹</label>
            <div class="col-sm-9">
              <input
                title="点击选择文件夹"
                id="directoryInput"
                multiple="multiple"
                webkitdirectory
                directory
                type="file"
                name="directoryInput"
              />
            </div>
          </div>
          <div class="alert alert-danger">
            <strong>警告！</strong>
            <p>此功能只能在Chrome浏览器下使用，文件数量暂时不要超过1000 </p>
            <p>点击提交后，操作成功后页面将自动跳转，期间请勿取消或重复点击</p>
          </div>
          <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-9">
              <button id="upload" class="btn btn-success">提交</button>
              <a href="./index.html"><button class="btn btn-default">取消</button></a>
            </div>
          </div>
          <!-- <br />
          <span>多个文件</span>
          <input type="file" id="multiplefile" name="multiplefile" multiple="multiple" /> -->
        </form>
      </div>
    </div>
    <script type="text/javascript">
      $(function() {
        var loading = false
        $('#directoryInput').change(function(e) {
          console.log($(this)[0].files)
        })
        $('#upload').click(function(e) {
          if(loading){
            alert('请勿重复点击')
            return false
          } 
          var projectname = $('#projectname').val()
          var projectversion = $('#projectversion').val()
          var directoryInput = $('#directoryInput')[0].files
          if (
            projectname == '' ||
            projectversion == '' ||
            new RegExp(/\s/).test(projectname) ||
            new RegExp(/\s/).test(projectversion)
          ) {
            alert('请填写完整参数，且不可输入空格')
            return false
          }
          if (directoryInput.length == 0) {
            alert('请选择文件夹')
            return false
          }
          loading =true
          $('#form-box').submit()
        })
      })
    </script>
  </body>
</html>
